package com.ruoyi.repayment.controller;

import com.aliyun.oss.OSS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;

import java.io.ByteArrayInputStream;
import java.util.Base64;
import java.util.Map;

@RestController
@RequestMapping("/loan/sq")
public class OssController {
    @Value("${oss.bucket}")
    private String bucketName;

    @Value("${oss.hostName}")
    private String hostName;

    @Autowired
    private OSS ossClient;

    //将base64的文件信息接收转换成图片信息用作合成合同
    @PostMapping("receptionBase64/{userId}")
    public void receptionBase64( @PathVariable("userId")Integer userId,@RequestBody Map map){
        String base64 = (String) map.get("images");
        String substring = base64.substring(base64.indexOf(",")+1);
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] sses = decoder.decode(substring);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sses);
        ossClient.putObject(bucketName,userId+".jpg",byteArrayInputStream);

        System.out.println("上传成功");
    }


}
